package com.gitee.feizns.zxw.web.controller.backstage;

import com.gitee.feizns.web.aspectj.decrypt.Decrypt;
import com.gitee.feizns.web.boot.decrypt.DecryptProperties;
import com.gitee.feizns.web.domain.result.Ret;
import com.gitee.feizns.zxw.domain.backstage.ao.auth.login.LoginAo;
import com.gitee.feizns.zxw.domain.backstage.vo.auth.key.PublicKeyVo;
import com.gitee.feizns.zxw.domain.backstage.vo.auth.login.LoginVo;
import com.gitee.feizns.zxw.service.backstage.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理员认证
 * @author feizns
 * @since 2019/9/9
 */
@RestController
@RequestMapping("/api/v1/backstage/auth")
public class AuthController {

    @Autowired
    private DecryptProperties decryptProperties;

    @Autowired
    private AuthService authService;

    /**
     * 登陆公钥
     * @return com.gitee.feizns.zxw.domain.backstage.vo.auth.key.PublicKeyVo
     */
    @GetMapping("/key/public")
    public Ret<PublicKeyVo> publicKey() {
        return Ret.ok(new PublicKeyVo(decryptProperties.getPublicKey()));
    }

    /**
     * 登陆
     * @param ao
     * @return com.gitee.feizns.zxw.domain.backstage.vo.auth.login.LoginVo
     */
    @Decrypt
    @PostMapping("/login")
    public Ret<LoginVo> login(@Validated @RequestBody LoginAo ao) {
        return Ret.ok(authService.login(ao));
    }

}
